﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Ajax.Controllers
{
    [Route("api/[controller]")]
    public class AjaxController : Controller
    {
        //FromBody  FromForm  FromHeader    (html传值位置)

        [HttpGet("GetVal")]
        public async Task<string> GetVal(string name, string age)
        {
            Thread.Sleep(1000);
            string Json = "[{\"姓名\":\"" + name + "\",\"年龄\":\"" + age + "\"}]";
            return await Task.FromResult(Json);

        }

        [HttpPost("PostVal")]
        public async Task<IActionResult> PostVal([FromBody]UserInfo user)
        {
            Thread.Sleep(1000);
            var us = await Task.FromResult(user);
            return Ok(us);

        }
    }
    public class UserInfo
    {

        public string name { get; set; }
        public int age { get; set; }
        public string sex { get; set; }
    }
}